/**
 * Generate code from /{{projectName}}-user/src/main/java/{{packageName}}/core/{{modules}}/service/impl/{{entities@SQL}}ServiceImpl.java.hbs
 */
// @SkipOverwrite
package cn.ibizlab.core.authentication.service.impl;

import cn.ibizlab.core.authentication.domain.AuthLog;
import cn.ibizlab.core.authentication.filter.AuthLogSearchContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import java.sql.Timestamp;

/**
 * 实体[认证日志] 服务对象接口实现
 *
 * @author generator
 */
@Slf4j
@Service("AuthLogService")
public class AuthLogServiceImpl extends AbstractAuthLogService {

    /**
     * 将数据库中long类型的登录时间转换为timestamp
     * @param context
     * @return
     */
    @Override
    public Page<AuthLog> searchLog(AuthLogSearchContext context) {
        Page<AuthLog> logs = super.searchLog(context);
        if(!ObjectUtils.isEmpty(logs)){
            for(AuthLog log : logs){
                if(!ObjectUtils.isEmpty(log.getTimestmp()))
                    log.setTime(new Timestamp(log.getTimestmp()));
            }
        }
        return logs;
    }

    /**
     * 将数据库中long类型的登录时间转换为timestamp
     * @param et
     * @return
     */
    @Override
    public AuthLog get(AuthLog et) {
        AuthLog log = super.get(et);
        if(log != null && !ObjectUtils.isEmpty(log.getTimestmp()))
            log.setTime(new Timestamp(log.getTimestmp()));
        return log;
    }
}